// import React from 'react'
import { round } from 'src/utils/utils';

/**
 * @method tooltipFormatter
 * @description
 * @param {Number} n 四舍五入保留n小数
 * @param {Array} [Number,String] [num,unit] value/num + unit
 * @return {String}
 */
export function tooltipFormatter(params, n, [num, unit] = [1, '']) {
  const p = params.reduce((values, it, index) => {
    const current_value = `${it.marker}${it.seriesName}:${round(Number(it.value / num), n)}${unit}`;
    if (params.length < 10) {
      return values === '' ? current_value : `${values}<br/>${current_value}`;
    }
    return `${values}${index && index % 2 === 0 ? '<br/>' : ''}<div style="width: 50%; display: inline-block;padding-right:10px;">${current_value}</div>`;
  }, '');
  return `${params[0].name}<br/>${p}`;
}
